package com.community.demo.beans.recursos;

import java.util.Date;
import java.util.List;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;

import org.primefaces.event.DateSelectEvent;
import org.primefaces.event.ScheduleEntrySelectEvent;
import org.primefaces.model.DefaultScheduleModel;
import org.primefaces.model.ScheduleEvent;
import org.primefaces.model.ScheduleModel;

import com.community.demo.beans.GenericBean;
import com.community.demo.model.Reserva;
import com.community.demo.model.TipoZona;
import com.community.demo.model.Zona;
import com.community.demo.services.TipoZonaServices;
import com.community.demo.services.ZonaServices;

@ManagedBean
@ViewScoped
public class ReservasZonasBean extends GenericBean {

	private static final long serialVersionUID = -1308800118109907672L;

	/** Objeto encargado del despliegue del componente calendario en la vista*/
	private ScheduleModel scheduleModel;
	/** Objeto contenedor de la informacion correcpondiente a una reserva*/
	private Reserva reserva;
	
	private List<TipoZona> tiposZona;
	
	private List<Zona> zonas;
	

	/**Constructor de la clase*/
	public ReservasZonasBean() {

		Date fefin = new Date();
		fefin.setHours(fefin.getHours() + 7);

		scheduleModel = new DefaultScheduleModel();
		reserva = new Reserva();
		reserva.setId("asd1");
		reserva.setTitle("Titulo");
		Date inicio = new Date();
		inicio.setDate(inicio.getDate() + 5);
		reserva.setStartDate(inicio);
		reserva.setEndDate(fefin);
		reserva.setEditable(true);
		scheduleModel.addEvent(reserva);

		Date fefin1 = new Date();
		fefin1.setHours(fefin1.getHours() - 30);
		Reserva reserva1 = new Reserva();
		reserva1.setId("asd2");
		reserva1.setTitle("Titulo");
		reserva1.setStartDate(fefin1);
		reserva1.setEndDate(new Date());
		reserva1.setEditable(true);
		scheduleModel.addEvent(reserva1);

		Date fefin2 = new Date();
		fefin2.setHours(fefin2.getHours() + 15);
		Reserva reserva2 = new Reserva();
		reserva2.setId("asd3");
		reserva2.setTitle("Titulo");
		reserva2.setStartDate(new Date());
		reserva2.setEndDate(fefin2);
		reserva2.setEditable(true);
		scheduleModel.addEvent(reserva2);

		Date fefin3 = new Date();
		fefin3.setHours(fefin3.getHours() + 6);
		Reserva reserva3 = new Reserva();
		reserva3.setId("asd4");
		reserva3.setTitle("Titulo");
		reserva3.setStartDate(new Date());
		reserva3.setEndDate(fefin3);
		reserva3.setEditable(true);
		scheduleModel.addEvent(reserva3);

	};

	public void onEventSelect(ScheduleEntrySelectEvent selectEvent) {
		System.out.println("EVENTO SELECCIONADO");
		ScheduleEvent event = selectEvent.getScheduleEvent();
		System.out.println("ID EVENTO " + event.getId().toString());
	}
	
	public void onDateSelect(DateSelectEvent selectEvent) {
		System.out.println("CORRIENDO");
		//Date selectedDate = selectEvent.getDate();
	}
	
	
	public Reserva getReserva() {
		return reserva;
	}

	public void setReserva(Reserva reserva) {
		this.reserva = reserva;
	}

	public ScheduleModel getScheduleModel() {
		return scheduleModel;
	}
	
	public void setScheduleModel(ScheduleModel scheduleModel) {
		this.scheduleModel = scheduleModel;
	}

	public List<TipoZona> getTiposZona() {
		if(this.tiposZona == null)
			tiposZona = TipoZonaServices.getTiposZona();
		return tiposZona;
	}

	public void setTiposZona(List<TipoZona> tiposZona) {
		this.tiposZona = tiposZona;
	}

	public List<Zona> getZonas() {
		if(zonas == null)
			zonas = ZonaServices.getZonas();
		return zonas;
	}

	public void setZonas(List<Zona> zonas) {
		this.zonas = zonas;
	}
	
}
